package com.ouyeel.wlxer.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.ouyeel.wlxer.R;
import com.ouyeel.wlxer.base.BaseAppStar;
import com.ouyeel.wlxer.bean.LoginOut;
import com.ouyeel.wlxer.util.SharePrefUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;


/**
 * Created by rankaifeng on 2017/10/19.
 */

public class LoginActivity extends BaseAppStar {
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindViews({R.id.edit_userName, R.id.edit_pwd})
    List<EditText> editTexts;
    private EditText editUserName, editPwd;
    private String mUserName, mPwd;

    @Override
    public int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        AppStart.appStart.finish();
        editUserName = editTexts.get(0);
        editPwd = editTexts.get(1);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                login();
            }
        });
    }

    private void login() {
//        mUserName = editUserName.getText().toString().trim();
//        mPwd = editPwd.getText().toString().trim();
//        if (StringUtils.isEmpty(mUserName)) {
//            showTost("请输入用户名！");
//            return;
//        }
//        if (StringUtils.isEmpty(mPwd)) {
//            showTost("请输入密码！");
//            return;
//        }
//        Map<String, String> map = new HashMap<>();
//        map.put("userCode", mUserName);
//        map.put("password", mPwd);
//        RequestBody requestBody = GsonUtil.getInstnse().changeBody(map);
//        LoginModel loginModel = new LoginModelImp();
//        loginModel.userLogin(this, requestBody);
        MainActivity.gotoActivity(this);
    }

    /**
     * 登陆成功
     *
     * @param loginOut
     */
    public void loginSuccess(LoginOut loginOut) {
        SharePrefUtil.saveString(LoginActivity.this, "token", loginOut.getToken());
        SharePrefUtil.saveString(LoginActivity.this, "role", loginOut.getRole());
        SharePrefUtil.saveString(LoginActivity.this, "driverId", loginOut.getDriverId());
        SharePrefUtil.saveString(LoginActivity.this, "clockstatus", loginOut.getClockstatus());
        SharePrefUtil.saveBoolean(this, "isLogin", true);
        Intent mIntent = new Intent(LoginActivity.this, MainActivity.class);
        SharePrefUtil.saveString(LoginActivity.this, "url", loginOut.getWeburl());
        startActivity(mIntent);
        finish();
    }

    public static void gotoActivity(Activity activity) {
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
    }
}
